multiple assignement with objects #193
Replies: 4 comments
-
I will try to explain to the best of my knowledge. I reserve the right to be completely wrong ;D var foo = {n: 1}; --> this is placing content in some point A in memory, "foo" is the address to point A. foo = {n: 2}; --> this is placing content in some point B in memory, "foo" has a new address, now to point B. Note that "bar" is unaltered, it stills point to content in address A. Then: I do not think that is a strange behavior to js, just that pointers are somewhat counterintuitive. |
Beta Was this translation helpful? Give feedback.
-
That would be indeed a very strange behavior — it's simply that the member access operator (the dot [
By the way, you couldn't do this in two lines without my fictional When you have pointers (e.g. In some languages, like C++, you can even do this: |
Beta Was this translation helpful? Give feedback.
-
I agree with your analysis, but I believe it could have it's place in the examples of wtfjs ! |
Beta Was this translation helpful? Give feedback.
-
PR is welcome. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
foo.x == undefined, but bar.x == foo
Beta Was this translation helpful? Give feedback.
All reactions